const connection = require("../app/database");

class ProfileService {
  // 查询用户全部信息
  async getUserMessageByUserId(userId) {
    const statement = `SELECT * FROM user_message WHERE user_id = ?;`;
    const [res, fields] = await connection.execute(statement, [userId]);
    return res[0];
  }
  // 插入用户信息
  async insertUserMessage(userId) {
    const statement = `INSERT INTO user_message (user_id) VALUES (?);`;
    await connection.execute(statement, [userId]);
  }
  // 修改用户邮箱
  async updateUserEmail(email, userId) {
    const statement = `UPDATE user_message SET email=? WHERE user_id=?;`;
    await connection.execute(statement, [email, userId]);
  }
  // 修改用户头像地址
  async updateUserAvatar(avatar, userId) {
    try {
      const statement = `UPDATE user_message SET avatar_url=? WHERE user_id=?;`;
      const [res] = await connection.execute(statement, [avatar, userId]);
    } catch (err) {
      console.log(err);
    }
  }
  // 修改用户电话
  async updateUserPhone(phone, userId) {
    const statement = `UPDATE user_message SET phone_number=? WHERE user_id=?`;
    await connection.execute(statement, [phone, userId]);
  }
  // 修改用户个人介绍
  async updateUserIntroduce(introduce, userId) {
    const statement = `UPDATE user_message SET introduce=? WHERE user_id=?;`;
    await connection.execute(statement, [introduce, userId]);
  }
}

module.exports = new ProfileService();
